package conexionjdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;

import utilitario.PropiedadesExterna;

public class ConexionSqlServerMigrar {

	private static String servidor_database = PropiedadesExterna.obtenerInstance().getServidor("servidor_database");;
	private static String usuario = PropiedadesExterna.obtenerInstance().getServidor("usuario");
	private static String password = PropiedadesExterna.obtenerInstance().getServidor("password");

	public static Connection crearConexion() {

		try {

			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			Connection conectarBd = DriverManager.getConnection("jdbc:sqlserver://" + servidor_database + "\\SQLEXPRESS:1433;databaseName=dbsistemachentty_v5", usuario, password);

			return conectarBd;

		} catch (ClassNotFoundException e) {

			JOptionPane.showConfirmDialog(null,
					"No se encontro el controlador de SQLServer!!!",
					"Sistema de Hernan",
					JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE);

			throw new RuntimeException(e);

		} catch (SQLException e) {

			JOptionPane.showConfirmDialog(null,
					"Error de Sentencia SQL!!!",
					"Sistema de Hernan",
					JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE);

			throw new RuntimeException(e);

		}
	}

	public static void main(String[] args) throws SQLException {

		Connection c = ConexionSqlServerMigrar.crearConexion();
		System.out.println("Cerrada : " + c.isClosed());
		c.close();
	}
}
